<template>
	<view class="container" style="background-size: 100% 100%" :style="{ backgroundImage: 'url(' + imageURL + ')' }">
		<view class="text">
			<view class="text_body">
				<p style="color: white">我用十年青春,赴你最后之约</p>
			</view>
		</view>


		<view class="padding-lg padding-top-xl flex flex-direction">
			<button @tap="login()" class="cu-btn block bg-gradual-green lg">
				登录
			</button>
		</view>



	</view>
</template>

<script>
	import {
		checkUser,
	} from "@/common/api.js";
	export default {
		onLoad() {
			// console.log(this.userInfo,"userInfo");
			this.imageURL = this.$imageURL
		},
		methods: {

			// 跳转
			async gotoPage() {
				await uni.switchTab({
					url: '/pages/index/index'
				});
			},
			//登录
			login() {

				if (!uni.getUserProfile) {
					uni.showModal({
						content: "uni.getUserProfile不可用",
						title: "提示"
					})
				}

				let that = this;
				// 调用接口请求openID
				wx.login({
					success(codeData) {
						uni.request({
							url: that.$baseUrl + '/wxLogin',
							method: 'POST',
							header: {
								'Content-Type': 'application/json'
							},
							data: {
								code: codeData.code,
								key: 'SGye9LQ^v&Ns7qUHw6Z'
							},
							success: res => {
								console.log(res, "wxLogin------------>>");
								if (res.statusCode === 200 && res.data.openid) {
									let variables = {
										openid: res.data.openid,
										scores_number: 10,
									}
									checkUser(variables).then(res => {
										console.log(res, "checkUser");
										if (res.code === 200 && res.data
											.insert_user_one
											.user_status === 1) {
											// 登录成功,保存用户数据,跳转到首页
											uni.setStorageSync('userInfo',
												res.data
												.insert_user_one)
											getApp().globalData.userInfo =
												res.data.insert_user_one
											that.gotoPage()
										} else if (res.code === 200 && res
											.data.insert_user_one
											.user_status === 0) {
											try {
												uni.clearStorageSync();
											} catch (e) {
												// error
											}
											// 账号禁用,提示用户
											uni.showModal({
												title: "账号禁用",
												content: "请联系管理员!"
											})
										} else {
											try {
												uni.clearStorageSync();
											} catch (e) {
												// error
											}
											// 获取用户信息失败,提示重试
											uni.showModal({
												title: "提示",
												content: "获取用户信息失败,请重试!"
											})
										}
									}).catch(err => {
										console.log(err, "checkUser");
									})
								} else {
									uni.showModal({
										title: "提示0",
										content: "action未返回openID"
									})
								}
							},
							fail: err => {
								console.log(err, "wxLogin------------>>");
								uni.showModal({
									title: "提示2",
									content: "获取微信接口失败,请重试!"
								})
							},
							complete: () => {}
						});


					},
				});




			},
		},
		computed: {
			// ...mapGetters([
			// 	"userInfo"
			// ])
		},
		data() {
			return {
				imageURL: "https://fendou.life/uploads/20230207/4f8cd2699d32510f732267b0221bb6ad.jpg",
				avatarUrl: "",
				nickName: "",

			};
		},
	};
</script>
<style scoped>
	.container {
		height: 100vh;
		width: 100vw;
	}

	.text {
		height: 70vh;
		width: 100%;

		/* display: flex; */
	}

	.text_body {
		text-align: center;
		line-height: 70vh;
		/* background: rgba(0, 0, 0, .2); */
		font-weight: 700;
	}

	.text_body>p {
		/* line-height: 70vh; */
		background: rgba(0, 0, 0, 0.2);
		font-weight: 700;
	}

	.button {
		padding: 40rpx;
	}
</style>
